// Table component for displaying data
use iced::{Element, widget::{column, row, text, container}};

/// Simple table component
pub fn data_table<'a, Message>(
    headers: &'a [String],
    rows: &'a [Vec<String>],
) -> Element<'a, Message>
where
    Message: 'a,
{
    let header_row = row(
        headers.iter()
            .map(|header| container(text(header)).into())
            .collect::<Vec<Element<'a, Message>>>()
    );

    let data_rows = rows.iter().map(|row_data| {
        row(
            row_data.iter()
                .map(|cell| container(text(cell)).into())
                .collect::<Vec<Element<'a, Message>>>()
        ).into()
    }).collect::<Vec<Element<'a, Message>>>();

    let mut table = column![header_row];
    for data_row in data_rows {
        table = table.push(data_row);
    }

    table.into()
}
